﻿using System;
using System.Collections.Generic;
using SharpGraphT.Sharp.System;

namespace SharpGraphT.Sharp.Sharp.Util;

public static class Objects {
    public static int Hash(params object[] values) =>
        ArrayExtension.GetHashCode(values);

    public new static bool Equals(object a, object b) =>
        a == b || a != null && a.Equals(b);

    public static bool Equals<T>(T a, T b) =>
        EqualityComparer<T>.Default.Equals(a, b);

    public static T RequireNonDefault<T>(T obj, string message = "") =>
        EqualityComparer<T>.Default.Equals(obj, default)
            ? throw new ArgumentDefaultException(message)
            : obj;

    public static bool IsDefault<T>(T obj) =>
        EqualityComparer<T>.Default.Equals(obj, default);

    public static T RequireNonNull<T>(T obj) where T : class =>
        obj ?? throw new ArgumentNullException();

    public static T RequireNonNull<T>(T obj, string message) where T : class =>
        obj ?? throw new ArgumentNullException(message);

    public static void Assert(bool b) {
        if (!b) {
            throw new AssertException();
        }
    }
}